package contact.domain;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class DAOContactGroup extends HibernateDaoSupport{
	
	public DAOContactGroup(){
	}
	
	public static DAOContactGroup createInstance(){
		return new DAOContactGroup();
	}

	public Long create(ContactGroup group){
		return (Long) getHibernateTemplate().save(group);
	}

	public Long createIfNotExists(ContactGroup group){
		List list = getHibernateTemplate().find("from ContactGroup group where group.groupName= ? ",group.getGroupName());
		if (list.size() == 0){
			return create(group);
		}
		return null;
	}

	public ContactGroup read(Long id){
		if (getHibernateTemplate() == null) System.out.println("NULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");
		return (ContactGroup) getHibernateTemplate().find("from ContactGroup group where group.id = ?",id).get(0);
	}

	public List<ContactGroup> readAll(){
		HibernateTemplate ht = getHibernateTemplate();
		return ht.find("from ContactGroup");
		//return getHibernateTemplate().find("from ContactGroup");
	}

	public void update(ContactGroup group){
		getHibernateTemplate().update(group);
	}

	public void delete (ContactGroup group){
		getHibernateTemplate().delete(group);
	}


	
}
